<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <h:panelGrid columns="7">
                        <h:outputLabel value="From Date"/>
                        <p:calendar id="fromDate" value="#{dealorDueController.fromDate}" navigator="false"
                                    pattern="dd MMMM yyyy hh mm ss a" >

                        </p:calendar>
                        <h:outputLabel value="To Date"/>
                        <p:calendar id="toDate" value="#{dealorDueController.toDate}" navigator="false" pattern="dd MMMM yyyy hh mm ss a" >

                        </p:calendar>
                        <p:commandButton value="Process Pharmacy Due" action="#{dealorDueController.fillPharmacyDue()}" ajax="false"  />
                        <p:commandButton value="Process Store Due" action="#{dealorDueController.fillStoreDue()}" ajax="false"  />
                        <p:commandButton value="Process All Due" action="#{dealorDueController.fillPharmacyStoreDue()}" ajax="false"  />

                    </h:panelGrid>

                    <p:dataTable 
                        id="lst" 
                        value="#{dealorDueController.items}" 
                        var="i"  
                        style="width: 100%;"
                        paginator="true"
                        paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                        rowsPerPageTemplate="5,10,15"
                        >
                        <p:columnGroup type="header">
                            <p:row>
                                <p:column headerText="GRN No">                                    
                                </p:column>                               
                                <p:column headerText="Billed Amount">                                    
                                </p:column>
                                <p:column headerText="Returned Amount">                                    
                                </p:column>
                                <p:column headerText="Paid Amount">                                    
                                </p:column>
                                <p:column headerText="Net Amount">                                    
                                </p:column>
                            </p:row>
                        </p:columnGroup>
                        <p:subTable value="#{i.bills}" var="b" >
                            <f:facet name="header">
                                <h:outputLabel  value="#{i.institution.name}"/>
                            </f:facet>
                            <p:column>        
                                <h:panelGroup rendered="#{b.transBoolean}">
                                    <h:outputLabel value="#{b.deptId}" />   
                                    <h:outputText value="( #{b.billType} )"></h:outputText>
                                </h:panelGroup>
                            </p:column>                           
                            <p:column style="text-align: right;">   
                                <h:panelGroup rendered="#{b.transBoolean}">
                                    <h:outputLabel value="#{b.netTotal}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>   
                                </h:panelGroup>
                            </p:column>
                            <p:column style="text-align: right;">     
                                <h:panelGroup rendered="#{b.transBoolean}">
                                    <h:outputLabel value="#{b.tmpReturnTotal}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>    
                                </h:panelGroup>
                            </p:column>
                            <p:column style="text-align: right;">    
                                <h:panelGroup rendered="#{b.transBoolean}">
                                    <h:outputLabel value="#{b.paidAmount}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>
                            <p:column style="text-align: right;">    
                                <h:panelGroup rendered="#{b.transBoolean}">
                                    <h:outputLabel value="#{b.tmpReturnTotal+b.netTotal+b.paidAmount}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </h:panelGroup>
                            </p:column>
                            <p:columnGroup type="footer">
                                <p:row>
                                    <p:column footerText="Total" colspan="1" />
                                    <p:column style="text-align: right;">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.total}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.returned}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.paidTotal}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{i.total+i.paidTotal+i.returned}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                </p:row>
                            </p:columnGroup>
                        </p:subTable>

                    </p:dataTable>
                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
